<template>
  <div>
    <van-nav-bar
      :title="
        ReplyObj.reply_count ? ReplyObj.reply_count + '条回复' : '暂无回复'
      "
      left-text="返回"
      left-arrow
      @click-left="$emit('close')"
    />
    <div class="content-reply">
      <commentArticle
        @update-is_liking="updateLiking"
        :CommitItemObj="ReplyObj"
        :index="index"
      />
      <!-- 全部回复 -->
      <van-cell-group>
        <van-cell title="全部回复" />
      </van-cell-group>
      <commentArticle
        v-for="(item, index) in ReplyList"
        :key="item.com_id"
        @update-is_liking="updateReplyLiking"
        :CommitItemObj="item"
        :index="index"
      />
      <div class="stare">没有更多了~~</div>
    </div>
    <div class="floor">
      <van-button @click="isReplyShow = true">评论</van-button>
    </div>
    <!-- 评论弹窗 -->
    <van-popup
      v-model="isReplyShow"
      close-icon-position="top-left"
      position="bottom"
      :style="{ height: '15%' }"
      ><commentPopup
        v-if="isReplyShow"
        @updata-popu="isReplyShow = false"
        @update-list="updateList"
        :art_id="art_id"
        :articleInfo="ReplyObj"
        :isReply="isReply"
    /></van-popup>
  </div>
</template>

<script>
import commentArticle from './commentArticle.vue'
import commentPopup from './commentPoup.vue'
import { getCommentAPI } from '@/api'
export default {
  name: '',
  components: {
    commentArticle,
    commentPopup
  },
  props: {
    ReplyObj: {
      type: Object,
      required: true
    },
    index: {
      type: Number,
      required: true
    },
    art_id: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      // 评论评论数组
      ReplyList: [],
      // 评论评论弹出层
      isReplyShow: false,
      // 判断是否为评论的评论
      isReply: false
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getCommentReply()
  },
  methods: {
    updateLiking(index, val) {
      this.$emit('updateLiking', index, val)
    },
    // 获取评论回复
    async getCommentReply() {
      const { data } = await getCommentAPI({
        type: 'c',
        source: this.ReplyObj.com_id
      })
      this.ReplyList = data.data.results
    },
    // 评论评论点赞
    updateReplyLiking(index, val) {
      this.ReplyList[index].is_liking = val
      if (val === true) {
        this.ReplyList[index].like_count++
      } else {
        this.ReplyList[index].like_count--
      }
    },
    // 发布成功事件
    updateList(obj) {
      this.ReplyList.unshift(obj)
      this.$emit('AddReply')
    }
  }
}
</script>

<style scoped lang="less">
.content-reply {
  padding: 92px 0;
}
:deep(.van-nav-bar__content) {
  box-shadow: 0 1px 2px 2px rgb(247, 247, 247);
  .van-nav-bar__title {
    color: #323233 !important;
  }
  background-color: #fff !important;
  color: #323233 !important;
  .van-icon-arrow-left {
    color: #323233 !important;
  }
}
.floor {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 102px;
  box-shadow: 0 -1px 2px 2px rgb(247, 247, 247);
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: deeppink;
  :deep(.van-button) {
    width: 640px;
    height: 80px;
    border-radius: 40px;
    background-color: #fff;
  }
}
.stare {
  text-align: center;
  align-items: center;
  margin: 0.42667rem 0;
  color: #969799;
  font-size: 0.37333rem;
  line-height: 0.64rem;
  border-color: #ebedf0;
  border-style: solid;
  border-width: 0;
}
</style>
